{include file="public/head"/}
<style>
    .layui-form-label {
        width: 130px;
    }

    .layui-input-block {
        margin-left: 160px;
    }

    #imgTable + .layui-table-view tbody > tr > td {
        padding: 0;
    }

    #imgTable + .layui-table-view tbody > tr > td > .layui-table-cell {
        height: 60px;
        line-height: 60px;
    }

    .tdImg {
        height: 30px;
        max-width: none;
        border: none;
        cursor: pointer;
    }

    .layui-table-view {
        margin: 0;
    }

    .layui-input-num {
        width: 100px;
    }

    .layui-input-title {
        width: 400px;
    }

    .layui-treeSelect .ztree li span.button.switch {
        position: relative;
        top: -6px;
    }

    .none {
        display: none;
    }

    #image img {
        max-width: 160px;
        max-height: 124px;
        overflow: hidden;
    }

    .layui-upload-img {
        width: 100%;
        height: 100%;

    }

    .delimages {
        position: relative;
        width: 92px;
        height: 92px;
        margin: 0 10px 10px 0;
        display: inline-block;
    }

    .click_delimages {
        position: absolute;
        bottom: 0;
        width: 100%;
        text-align: center;
        color: #fff;
        background-color: #9e9e9ea1;
        cursor: pointer;
    }

    .spandiv {
        background: #3C8DBC;
        color: #fff !important;
        padding: 9px 13px !important;
        border-radius: 2px;
        cursor: pointer;
    }

    #addformcate {
        background: #3C8DBC;
        color: #fff !important;
        padding: 9px 13px !important;
        border-radius: 2px;
        cursor: pointer;
    }

    #showformat {
        margin-top: 10px;
    }

    .showformatdiv {
        border: 1px solid #eee;
        padding: .5rem .75rem;
        margin-bottom: .5rem;
        border-radius: .15rem;
    }

    .format_title {
        display: inline-block;
        width: 73%;
    }

    .addformatdiv {
        width: 200px;
        display: inline-block;
    }

    .addform {
        float: right;
        background: #3C8DBC;
        color: #fff !important;
        padding: 9px 6px !important;
        border-radius: 2px;
        cursor: pointer;
    }

    .attr-item {
        display: inline-block;
        background: #eee;
        margin-right: 1rem;
        margin-top: .5rem;
    }

    .attr-item .attr-name {
        padding: .15rem .75rem;
        display: inline-block;
    }

    .attr-item .attr-delete {
        padding: .24rem .6rem;
        background: #d4cece;
        color: #fff;
        font-size: 1rem;
        font-weight: bold;
        cursor: pointer;
    }

    .format_all_stock_num, .format_all_price, .format_stock_num, .format_price {
        width: 100px;
        display: inline-block;
    }

    .format_image {
        width: 200px;
        display: inline-block;
    }

    .tablediv {
        border-color: #e6e6e6;
    }

    .tablediv td, .tablediv th {
        padding: .75rem;
    }

    .tag-item {
        display: inline-block;
        background: #eee;
        margin-right: 1rem;
        margin-top: .5rem;
    }

    .tag-item .tag-name {
        padding: .15rem .75rem;
        display: inline-block;
    }

    .tag-item .tag-delete {
        padding: .24rem .6rem;
        background: #d4cece;
        color: #fff;
        font-size: 1rem;
        font-weight: bold;
        cursor: pointer;
    }

    .addtagspan {
        float: right;
        background: #3C8DBC;
        color: #fff !important;
        padding: 9px 6px !important;
        border-radius: 2px;
        cursor: pointer;
    }
</style>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body" pad15>
                    <div class="layui-form" wid100 lay-filter="">
                        <div class="layui-tab">
                            <ul class="layui-tab-title">
                                <li class="layui-this">商品设置</li>
                            </ul>
                            <div class="layui-tab-content">
                                <div class="layui-tab-item layui-show">
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">所属分类</label>
                                            <div class="layui-input-inline">
                                                <select lay-verify="required" name="cid" id="cid">
                                                    <option value="">请选择分类</option>
                                                    {volist name="categorys" id="vo"}
                                                        <option {if condition="isset($info)&&($info.cid eq $vo['category_id'])"}selected{/if}
                                                                value="{$vo.category_id}">{$vo.lefthtml}{$vo.category_name}</option>
                                                    {/volist}
                                                </select>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">商品名称</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="title" lay-verify="required"
                                                       value="{$info.title|default=''}" placeholder="商品名称"
                                                       class="layui-input">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">商品原价</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="origin_price" lay-verify="required"
                                                       value="{$info.origin_price|default=''}" placeholder="商品原价"
                                                       class="layui-input">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">商品现价</label>
                                            <div class="layui-input-inline">
                                                <input type="number" name="present_price" lay-verify="required"
                                                       value="{$info.present_price|default=''}" placeholder="商品现价"
                                                       class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">定金价格</label>
                                            <div class="layui-input-inline">
                                                <input type="number" name="deposit_price" lay-verify="required"
                                                       value="{$info.deposit_price|default=''}" placeholder="定金价格"
                                                       class="layui-input">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">抵扣金额(立减)</label>
                                            <div class="layui-input-inline">
                                                <input type="number" name="deduction_price" lay-verify="required"
                                                       value="{$info.deduction_price|default=''}" placeholder="定金价格"
                                                       class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">有效期</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="term" lay-verify="required"
                                                       value="{$info.term|default=''}" placeholder="有效期"
                                                       class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">售后服务</label>
                                            <div class="layui-input-inline">
                                                <textarea id="service" lay-verify="required" name="service" rows="3"
                                                          cols="60"
                                                          style="border-color: #D2D2D2!important">{$info.service|default=''}</textarea>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">使用说明</label>
                                            <div class="layui-input-inline">
                                                <textarea id="explain" lay-verify="required" name="explain" rows="3"
                                                          cols="60"
                                                          style="border-color: #D2D2D2!important">{$info.explain|default=''}</textarea>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">门店名称</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="store_name" lay-verify="required"
                                                       value="{$info.store_name|default=''}" placeholder="门店名称"
                                                       class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">门店地址</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="store_address" lay-verify="required"
                                                       value="{$info.store_address|default=''}" placeholder="门店地址"
                                                       class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">门店电话</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="store_mobile" lay-verify="required"
                                                       value="{$info.store_mobile|default=''}" placeholder="门店电话"
                                                       class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">封面图(主图)</label>
                                        <div class="layui-input-inline">
                                            <input name="cover" lay-verify="required" id="cover"
                                                   value="{$info.cover|default=''}" placeholder="图片地址"
                                                   class="layui-input">
                                        </div>
                                        <div class="layui-input-inline layui-btn-container" style="width: auto;">
                                            <button type="button" class="layui-btn" id="thumbUpload">
                                                <i class="layui-icon">&#xe67c;</i>上传图片
                                            </button>
                                            <button class="layui-btn layui-btn-primary" layadmin-event="logoShow">查看图片
                                            </button>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">商品轮播:</label>
                                        <div class="layui-input-block">
                                            <div class="layui-upload">
                                                <button type="button" class="layui-btn" id="images">多图片上传</button>
                                                <blockquote class="layui-elem-quote layui-quote-nm"
                                                            style="margin-top: 10px;border: none">
                                                    <div class="layui-upload-list" id="imagesshow"></div>
                                                </blockquote>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">商品内容</label>
                                        <div class="layui-input-inline">
                                            <textarea placeholder="{:lang('pleaseEnter')}商品详情" lay-verify="required"
                                                      rows="20" name="content" id="content"
                                                      class="layui-textarea editor">{$info.content|default=''}</textarea>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">库存</label>
                                            <div class="layui-input-inline">
                                                <input type="number" name="stock" lay-verify="required"
                                                       lay-verify="required" value="{$info.stock|default=999}"
                                                       placeholder="库存" class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="hidden" name="id" value="{$info.id|default=''}">
                                <button class="layui-btn" lay-submit lay-filter="edit-but">确认保存</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

{include file="public/foot"/}
<script src="/static/vend/kindeditor/kindeditor-min.js" type="text/javascript"></script>
<script language="javascript">
    var editor;
    KindEditor.ready(function (K) {
        editor = K.create('.editor', {
            resizeType: 1,
            allowPreviewEmoticons: false,
            allowImageUpload: false,
            afterBlur: function () {
                this.sync();
            }
        });
    });
</script>

<script>
    layui.config({
        base: '__LAYDMIN__/', {if config('app.app_debug')}version: true{/if}
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'admin', 'table', 'colorpicker', 'upload'], function () {
        var $ = layui.$, admin = layui.admin, table = layui.table, element = layui.element, form = layui.form,
            util = layui.util, upload = layui.upload, colorpicker = layui.colorpicker;
        //编辑提交
        var uri = "{if isset($info['id'])}{:url(SYS_PATH.'/'.CONTROLLER.'/edit')}{else}{:url(SYS_PATH.'/'.CONTROLLER.'/add')}{/if}";
        form.on('submit(edit-but)', function (data) {
            admin.req({
                url: uri //实际使用请改成服务端真实接口
                , type: 'post'
                , data: data.field
                , success: function (res) {
                    if (res.code == 0) {
                        window.top.layer.msg(res.msg, {icon: 1, time: 1000,shade:[0.5,'#000000']}, function () {
                            layer.closeAll("iframe");
                            //刷新父页面
                            parent.location.reload();
                        });
                    } else {
                        window.top.layer.msg(res.msg, {icon: 2, time: 1000,shade:[0.5,'#000']});
                        return;
                    }
                }

            });
        });

        //上传logo
        var thumb = $('#cover');
        upload.render({
            url: '{:url(SYS_PATH."/uploads/upimg")}'
            , elem: '#thumbUpload'
            , done: function (res) {
                if (res.code == 0) {
                    thumb.val(res.url);
                    //logo.parent().append('<input type="hidden" name="logo_aid" value="'+res.aid+'">')
                } else {
                    layer.msg(res.msg, {icon: 5});
                }
            }
        });
        //查看logo
        admin.events.logoShow = function (othis) {
            var src = thumb.val();
            layer.photos({
                photos: {
                    "title": "查看图片" //相册标题
                    , "data": [{
                        "src": src //原图地址
                    }]
                }
                , shade: 0.01
                , closeBtn: 1
                , anim: 5
            });
        };

        // 获取多图
        {if isset($info['id'])}
        $(function () {
            var id = {$id};
            var url = "{:url(SYS_PATH.'/Goods/getImages')}";
            $.ajax({
                url: url,
                type: 'get',
                data:{id:id},
                success: function (req) {
                    var list = JSON.parse(req); //返回的数据
                    for (var p in list) {
                        $('#imagesshow').append('' +
                            '<div class="delimages">' +
                            '<input name="images[]" type="hidden" value="' + list[p] + '">' +
                            '<img src="' + list[p] + '" alt="' + list[p] + '" class="layui-upload-img">' +
                            '<div class="click_delimages">点击删除</div>' +
                            '</div>');
                    }
                }
            });
        });
        {/if}

        //多图片上传
        upload.render({
            url: '{:url(SYS_PATH."/uploads/upimg")}',
            elem: '#images',
            multiple: true,
            done: function (res) {
                console.log(res);
                //上传完毕
                $('#imagesshow').append('<div class="delimages"><input name="images[]" type="hidden" value="' + res.url + '"><img src="' + res.url + '" alt="' + res.url + '" class="layui-upload-img"><div class="click_delimages">点击删除</div></div>');

            }
        });

        $(document).off("click", ".click_delimages");
        $(document).on('click', '.click_delimages', function () {
            $(this).parent().remove();
        });
    });
</script>
</body>
</html>